package com.xfc.sde.dto;


import com.xfc.sde.component.DataSourceContext;
import org.springframework.jdbc.datasource.lookup.AbstractRoutingDataSource;

import javax.sql.DataSource;

public class MultiRouteDataSource extends AbstractRoutingDataSource {
    @Override
    protected Object determineCurrentLookupKey() {
        //通过绑定线程的数据源上下文实现多数据源的动态切换
        return DataSourceContext.getDataSource();
    }

    public DataSource getDataSource(String key) {
        return (DataSource) super.getResolvedDataSources().get(key);
    }

}
